<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./vue.js"></script>
</head>

<body>
    <div id="app">
        <h2>{{str}}</h2>
        <button @click='start'>点击我,让文字跑起来</button>
        <button @click='stop'>给我停下来</button>

        <button @click='moving'>点击我,设置定时器让文字跑起来</button>

    </div>
    <script>
   new Vue({
            el: '#app',
            data: {
                str: '我是vue小白, 准备进阶成大腿了 哈哈哈哈',
                timeId:'',
                // 是vue小白, 准备进阶成大腿了 哈哈哈哈我
            },
            methods: {
                //点击我,让文字跑起来   想尽一切办法去操作data 里面东西
                start() {   
                   
                    var start = this.str.substring(0, 1); //我
                    var end = this.str.substring(1); //是vue小白, 准备进阶成大腿了 哈哈哈哈
                    this.str = end + start;
                },

                moving() {
                    var This=this
                    // if(this.timeId!==null) return 
                    clearInterval(this.timeId)
                    This.timeId= setInterval(function () {       //this  指向了window
                        var start = This.str.substring(0, 1); //我
                        var end = This.str.substring(1); //是vue小白, 准备进阶成大腿了 哈哈哈哈
                        This.str = end + start;
                    }, 500)
    
                },
                moving2(){
                    setInterval(()=>{
                        var start = this.str.substring(0, 1); //我
                        var end = this.str.substring(1); //是vue小白, 准备进阶成大腿了 哈哈哈哈
                        this.str = end + start;
                    },1000)
                },
                stop(){
                    clearInterval(this.timeId)
                    this.timeId=null;
                }


            }
        })
    </script>
</body>

</html>